#include <vector>
#include <iostream>
#include <queue>

using namespace std;

class Solution {
public:
    vector<string> summaryRanges(vector<int>& nums) {
        if (nums.size() == 0) {
            return {};
        }
        priority_queue<int, vector<int>, greater<int>> queue;
        for (int num : nums) {
            queue.push(num);
        }
        int begin = queue.top();
        int end = begin;
        queue.pop();
        vector<string> ans;
        while (queue.size() > 0) {
            int val = queue.top();
            queue.pop();
            if (val == end + 1) {
                end++;
            } else {
                if (end != begin) {
                    ans.push_back(to_string(begin) + "->" + to_string(end));
                } else {
                    ans.push_back(to_string(begin));
                }
                begin = val;
                end = val;
            }
        }
        if (end != begin) {
            ans.push_back(to_string(begin) + "->" + to_string(end));
        } else {
            ans.push_back(to_string(begin));
        }
        return ans;
    }
};